<template>
	<view class="orderDetailOuter">
		<!-- 待发货 -->
		<view class="waitConsignment">
			<view>{{orderDetailData.text_status}}</view>
			<view>订单号：{{orderDetailData.order_id}}<text>复制</text></view>
			<view>下单时间：{{orderDetailData.utime}}</view>
		</view>

		<!-- 收件人 -->
		<view class="addressee">
			<view>收件人：{{orderDetailData.ship_name}}</view>
			<view>{{orderDetailData.ship_area_name}} {{orderDetailData.ship_address}}</view>
		</view>

		<!-- 商品列表 -->
		<view class="orderList">
			<view class="order_item" v-for="item in orderDetailData.items" :key="item.goods_id">
				<view class="orderList_l">
					<image :src="item.image_url" mode=""></image>
				</view>
				<view class="orderList_c">
					<view>{{item.name}}</view>
					<view>{{item.addon}}</view>
				</view>
				<view class="orderList_r">
					<view>￥{{item.price}}</view>
					<view>x {{item.nums}}</view>
				</view>
			</view>
		</view>

		<!-- 支付 -->
		<view class="payList">
			<view class="payItem">
				<text>商品总价</text>
				<text>￥{{orderDetailData.goods_amount}}</text>
			</view>
			<view class="payItem">
				<text>运费</text>
				<text>￥{{orderDetailData.cost_freight}}</text>
			</view>
			<view class="payItem">
				<text>订单总价</text>
				<text class="moneySum">￥{{orderDetailData.order_amount}}</text>
			</view>
			<view class="payItem" v-if="(orderDetailData.pay_status === 1 && orderDetailData.status ===3)===true?false:true">
				<text>支付方式</text>
				<text>{{orderDetailData.payment_name}}</text>
			</view>
			<view class="payItem" v-if="(orderDetailData.pay_status === 1 && orderDetailData.status ===3)===true?false:true">
				<text>支付时间</text>
				<text>{{orderDetailData.payment_time}}</text>
			</view>
		</view>

		<view class="footer">
			<!-- pay_status -->
			<view class="ft" v-if="orderDetailData.status === 1&& orderDetailData.pay_status ===2">
				申请售后
			</view>
			<view class="dfk" v-if="orderDetailData.status === 1&& orderDetailData.pay_status ===1">
				<view @click="cancelOrder">取消订单</view>
				<view @click="nowPay">立即支付</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		serviceApi
	} from '../../api/paiModule/home.js'
	export default {
		data() {
			return {
				orderId: '',
				orderDetailData: {}
			};
		},
		onLoad(options) {
			this.orderId = options.order_id
		},
		onShow() {
			this.getOrderDetail()
		},
		methods: {
			// 获取订单详情
			async getOrderDetail(data) {
				const {
					data: res
				} = await serviceApi({
					method: "order.details",
					order_id: this.orderId,
					token: uni.getStorageSync('token')
				})
				this.orderDetailData = res.data
			},

			// 立即支付
			nowPay() {
				uni.navigateTo({
					url: `/pages/pay/pay?ids=${this.orderDetailData.order_id}&type=${this.orderDetailData.order_type}`
				})
			},

			// 取消订单
			async cancelOrder() {
				const that = this
				uni.showModal({
					title: '提示',
					content: '确认要取消订单吗？',
					success: async function(res) {
						if (res.confirm) {
							const {
								data: res
							} = await serviceApi({
								method: "order.cancel",
								order_ids: that.orderDetailData.order_id,
								token: uni.getStorageSync('token')
							})
							that.getOrderDetail()
						} else {}
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.orderDetailOuter {
		height: 93.4vh;
		background-color: #f8f8f8;
		padding-top: 1px;
		position: relative;

		.waitConsignment {
			background-color: #fff;
			margin-top: 10px;
			font-size: 12px;
			padding: 10px;
			line-height: 20px;
			color: #848484;

			&>view {
				&:first-child {
					font-weight: bold;
					font-size: 13spx;
					color: #000;
				}

				&:nth-child(2) {
					text {
						display: inline-block;
						transform: scale(0.8);
						border: 1px solid #848484;
						padding: 0 4px;
					}
				}
			}
		}

		.addressee {
			background-color: #fff;
			margin-top: 10px;
			padding: 10px;
			font-size: 12px;
			line-height: 20px;

			&>view {
				&:first-child {
					font-size: 13px;
					font-weight: bold;
				}

				&:last-child {
					color: #848484;
				}
			}
		}

		.orderList {
			background-color: #fff;
			margin-top: 10px;
			padding: 10px;

			.order_item {
				display: flex;
				align-items: flex-start;
				padding: 10px 0;
				border-bottom: 1px solid #f0f0f0;

				.orderList_l {
					width: 60px;
					height: 70px;
					margin-right: 10px;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.orderList_c {
					width: 50%;
					font-size: 13px;
					margin-right: 20px;

					&>view {
						&:first-child {
							overflow-wrap: anywhere;
							text-overflow: -o-ellipsis-lastline;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 2;
							line-clamp: 2;
							-webkit-box-orient: vertical;
						}

						&:last-child {
							line-height: 20px;
							color: #848484;
						}
					}
				}

				.orderList_r {
					font-size: 12px;
					display: flex;
					flex-direction: column;
					align-items: flex-end;
					justify-content: center;

					&>view {
						&:last-child {
							margin-top: 20px;
							color: #848484;
						}
					}
				}

			}

		}

		.payList {
			background-color: #fff;
			margin-top: 10px;
			font-size: 12px;
			color: #848484;
			padding: 10px;
			line-height: 18px;

			.payItem {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-right: 40px;

				.moneySum {
					color: #e30000;
				}
			}
		}

		.footer {
			position: absolute;
			bottom: 0;
			left: 0;
			right: 0;
			height: 30px;
			background-color: #fff;
			display: flex;
			align-items: center;

			.ft {
				width: 70px;
				font-size: 12px;
				border: 1px solid;
				padding: 2px 0px;
				text-align: center;
				position: absolute;
				right: 10px;
				top: 50%;
				transform: translateY(-50%);
			}

			.dfk {
				width: 100px;
				font-size: 12px;
				width: 50%;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				position: absolute;
				right: 0px;


				view {
					border: 1px solid;
					padding: 2px 6px;
					margin-right: 10px;

					&:first-child {
						border: 1px solid #848484;
					}
				}
			}
		}
	}
</style>